package com.example.myapplication.pages;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.example.myapplication.view_type.ListAdapter;
import com.example.myapplication.bean.Person;
import com.example.myapplication.dao.MySQLiteOpenHelper;
import com.example.myapplication.databinding.ActivityPage1Binding;
import com.example.myapplication.service.SharedPreferencesService;

import java.util.List;

/**
 * 1：分类查询家人界面
 */
public class page_1 extends Fragment {
    private ActivityPage1Binding page1Binding;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        // 初始化布局，使用inflate方法将布局文件 activity_page1.xml 绑定到 page1Binding 对象。
        page1Binding = ActivityPage1Binding.inflate(inflater, container, false);
        // 从数据库中查询用户数据，存储在userList列表中。
        Integer userId = (Integer) SharedPreferencesService.getUserInfo(getContext()).get("userId");
        List<Person> personList = new MySQLiteOpenHelper(getContext()).queryPersonByCondition(5, null, 1, userId);
        // 再次调用 inflate 方法重新加载布局
        page1Binding = ActivityPage1Binding.inflate(getLayoutInflater());
        // 创建 ListAdapter 对象，并将其设置为 ListView 的适配器
        ListAdapter listAdapter = new ListAdapter(personList, getContext());
        page1Binding.relation1.setAdapter(listAdapter);
        // 返回ConstraintLayout根视图
        return page1Binding.getRoot();
    }
}